1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.PopoverMenu; 26 27 private import gio.MenuModel; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gtk.Popover; 32 private import gtk.Widget; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 36 37 /** 38 * `GtkPopoverMenu` is a subclass of `GtkPopover` that implements menu 39 * behavior. 40 * 41 *  42 * 43 * `GtkPopoverMenu` treats its children like menus and allows switching 44 * between them. It can open submenus as traditional, nested submenus, 45 * or in a more touch-friendly sliding fashion. 46 * 47 * `GtkPopoverMenu` is meant to be used primarily with menu models, 48 * using [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put 49 * other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover, 50 * you can use [method@Gtk.PopoverMenu.add_child]. 51 * 52 * For more dialog-like behavior, use a plain `GtkPopover`. 53 * 54 * ## Menu models 55 * 56 * The XML format understood by `GtkBuilder` for `GMenuModel` consists 57 * of a toplevel `<menu>` element, which contains one or more `<item>` 58 * elements. Each `<item>` element contains `<attribute>` and `<link>` 59 * elements with a mandatory name attribute. `<link>` elements have the 60 * same content model as `<menu>`. Instead of `<link name="submenu">` 61 * or `<link name="section">`, you can use `<submenu>` or `<section>` 62 * elements. 63 * 64 * ```xml 65 * <menu id='app-menu'> 66 * <section> 67 * <item> 68 * <attribute name='label' translatable='yes'>_New Window</attribute> 69 * <attribute name='action'>app.new</attribute> 70 * </item> 71 * <item> 72 * <attribute name='label' translatable='yes'>_About Sunny</attribute> 73 * <attribute name='action'>app.about</attribute> 74 * </item> 75 * <item> 76 * <attribute name='label' translatable='yes'>_Quit</attribute> 77 * <attribute name='action'>app.quit</attribute> 78 * </item> 79 * </section> 80 * </menu> 81 * ``` 82 * 83 * Attribute values can be translated using gettext, like other `GtkBuilder` 84 * content. `<attribute>` elements can be marked for translation with a 85 * `translatable="yes"` attribute. It is also possible to specify message 86 * context and translator comments, using the context and comments attributes. 87 * To make use of this, the `GtkBuilder` must have been given the gettext 88 * domain to use. 89 * 90 * The following attributes are used when constructing menu items: 91 * 92 * - "label": a user-visible string to display 93 * - "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html) 94 * - "action": the prefixed name of the action to trigger 95 * - "target": the parameter to use when activating the action 96 * - "icon" and "verb-icon": names of icons that may be displayed 97 * - "submenu-action": name of an action that may be used to track 98 * whether a submenu is open 99 * - "hidden-when": a string used to determine when the item will be hidden. 100 * Possible values include "action-disabled", "action-missing", "macos-menubar". 101 * This is mainly useful for exported menus, see [method@Gtk.Application.set_menubar]. 102 * - "custom": a string used to match against the ID of a custom child added with 103 * [method@Gtk.PopoverMenu.add_child], [method@Gtk.PopoverMenuBar.add_child], 104 * or in the ui file with `<child type="ID">`. 105 * 106 * The following attributes are used when constructing sections: 107 * 108 * - "label": a user-visible string to use as section heading 109 * - "display-hint": a string used to determine special formatting for the section. 110 * Possible values include "horizontal-buttons", "circular-buttons" and 111 * "inline-buttons". They all indicate that section should be 112 * displayed as a horizontal row of buttons. 113 * - "text-direction": a string used to determine the `GtkTextDirection` to use 114 * when "display-hint" is set to "horizontal-buttons". Possible values 115 * include "rtl", "ltr", and "none". 116 * 117 * The following attributes are used when constructing submenus: 118 * 119 * - "label": a user-visible string to display 120 * - "icon": icon name to display 121 * 122 * Menu items will also show accelerators, which are usually associated 123 * with actions via [method@Gtk.Application.set_accels_for_action], 124 * [id@gtk_widget_class_add_binding_action] or 125 * [method@Gtk.ShortcutController.add_shortcut]. 126 * 127 * # CSS Nodes 128 * 129 * `GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content 130 * to it, therefore it has the same CSS nodes. It is one of the cases that add 131 * a .menu style class to the popover's main node. 132 * 133 * # Accessibility 134 * 135 * `GtkPopoverMenu` uses the %GTK_ACCESSIBLE_ROLE_MENU role, and its 136 * items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM, 137 * %GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or 138 * %GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the 139 * action they are connected to. 140 */ 141 public class PopoverMenu : Popover 142 { 143 /** the main Gtk struct */ 144 protected GtkPopoverMenu* gtkPopoverMenu; 145 146 /** Get the main Gtk struct */ 147 public GtkPopoverMenu* getPopoverMenuStruct(bool transferOwnership = false) 148 { 149 if (transferOwnership) 150 ownedRef = false; 151 return gtkPopoverMenu; 152 } 153 154 /** the main Gtk struct as a void* */ 155 protected override void* getStruct() 156 { 157 return cast(void*)gtkPopoverMenu; 158 } 159 160 /** 161 * Sets our main struct and passes it to the parent class. 162 */ 163 public this (GtkPopoverMenu* gtkPopoverMenu, bool ownedRef = false) 164 { 165 this.gtkPopoverMenu = gtkPopoverMenu; 166 super(cast(GtkPopover*)gtkPopoverMenu, ownedRef); 167 } 168 169 170 /** */ 171 public static GType getType() 172 { 173 return gtk_popover_menu_get_type(); 174 } 175 176 /** 177 * Creates a `GtkPopoverMenu` and populates it according to @model. 178 * 179 * The created buttons are connected to actions found in the 180 * `GtkApplicationWindow` to which the popover belongs - typically 181 * by means of being attached to a widget that is contained within 182 * the `GtkApplicationWindow`s widget hierarchy. 183 * 184 * Actions can also be added using [method@Gtk.Widget.insert_action_group] 185 * on the menus attach widget or on any of its parent widgets. 186 * 187 * This function creates menus with sliding submenus. 188 * See [ctor@Gtk.PopoverMenu.new_from_model_full] for a way 189 * to control this. 190 * 191 * Params: 192 * model = a `GMenuModel` 193 * 194 * Returns: the new `GtkPopoverMenu` 195 * 196 * Throws: ConstructionException GTK+ fails to create the object. 197 */ 198 public this(MenuModel model) 199 { 200 auto __p = gtk_popover_menu_new_from_model((model is null) ? null : model.getMenuModelStruct()); 201 202 if(__p is null) 203 { 204 throw new ConstructionException("null returned by new_from_model"); 205 } 206 207 this(cast(GtkPopoverMenu*) __p); 208 } 209 210 /** 211 * Creates a `GtkPopoverMenu` and populates it according to @model. 212 * 213 * The created buttons are connected to actions found in the 214 * action groups that are accessible from the parent widget. 215 * This includes the `GtkApplicationWindow` to which the popover 216 * belongs. Actions can also be added using [method@Gtk.Widget.insert_action_group] 217 * on the parent widget or on any of its parent widgets. 218 * 219 * The only flag that is supported currently is 220 * %GTK_POPOVER_MENU_NESTED, which makes GTK create traditional, 221 * nested submenus instead of the default sliding submenus. 222 * 223 * Params: 224 * model = a `GMenuModel` 225 * flags = flags that affect how the menu is created 226 * 227 * Returns: the new `GtkPopoverMenu` 228 * 229 * Throws: ConstructionException GTK+ fails to create the object. 230 */ 231 public this(MenuModel model, GtkPopoverMenuFlags flags) 232 { 233 auto __p = gtk_popover_menu_new_from_model_full((model is null) ? null : model.getMenuModelStruct(), flags); 234 235 if(__p is null) 236 { 237 throw new ConstructionException("null returned by new_from_model_full"); 238 } 239 240 this(cast(GtkPopoverMenu*) __p, true); 241 } 242 243 /** 244 * Adds a custom widget to a generated menu. 245 * 246 * For this to work, the menu model of @popover must have 247 * an item with a `custom` attribute that matches @id. 248 * 249 * Params: 250 * child = the `GtkWidget` to add 251 * id = the ID to insert @child at 252 * 253 * Returns: %TRUE if @id was found and the widget added 254 */ 255 public bool addChild(Widget child, string id) 256 { 257 return gtk_popover_menu_add_child(gtkPopoverMenu, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(id)) != 0; 258 } 259 260 /** 261 * Returns the menu model used to populate the popover. 262 * 263 * Returns: the menu model of @popover 264 */ 265 public MenuModel getMenuModel() 266 { 267 auto __p = gtk_popover_menu_get_menu_model(gtkPopoverMenu); 268 269 if(__p is null) 270 { 271 return null; 272 } 273 274 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p); 275 } 276 277 /** 278 * Removes a widget that has previously been added with 279 * gtk_popover_menu_add_child(). 280 * 281 * Params: 282 * child = the `GtkWidget` to remove 283 * 284 * Returns: %TRUE if the widget was removed 285 */ 286 public bool removeChild(Widget child) 287 { 288 return gtk_popover_menu_remove_child(gtkPopoverMenu, (child is null) ? null : child.getWidgetStruct()) != 0; 289 } 290 291 /** 292 * Sets a new menu model on @popover. 293 * 294 * The existing contents of @popover are removed, and 295 * the @popover is populated with new contents according 296 * to @model. 297 * 298 * Params: 299 * model = a `GMenuModel` 300 */ 301 public void setMenuModel(MenuModel model) 302 { 303 gtk_popover_menu_set_menu_model(gtkPopoverMenu, (model is null) ? null : model.getMenuModelStruct()); 304 } 305 }